﻿using System;
using System.Collections;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OpenGado.DATA;
using OpenGado.DATA.Entities;
using Telerik.Web.UI;

namespace OpenGado
{
    public partial class CategoryForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void LvCategories_ItemCommand(object sender, Telerik.Web.UI.RadListViewCommandEventArgs e)
        {

            if (e.CommandName == RadListView.UpdateCommandName)
            {
                int catId = 0;

                RadListViewDataItem editedItem = e.ListViewItem as RadListViewDataItem;
                int.TryParse(editedItem.GetDataKeyValue("CategoryId").ToString(), out catId);

                Hashtable newValues = new Hashtable();

                editedItem.ExtractValues(newValues);

                // do the normal crud as if binding doesnt exits 

                Categories cat = new Categories();
                cat.CategoryId = catId;
                cat.CategoryName = newValues["CategoryName"].ToString();

                CategoryDataControl.Instance.Save(cat);


            }
        }
    }
}